[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
* Provided by Concentric Data Systems, Inc. as an example. This Clipper
* code has not been certified - use at your own risk. The Version 3 R&R
* configuration file structure is subject to change without notice.
*
* This function opens the configuration file specified, and fills a public
* array of the same name with the eight printer names, leaving names blank
* where not defined. For example, getprts("RR.CNF") fills an array named RR
* with the names of the eight printers defined in the configuration file
* named RR.CNF.

FUNCTION getprts
PARAMETERS cnfname
PRIVATE count, data, dataptr, handle, printer, offset[8], rectype

IF .NOT. '.' $ cnfname
   cnfname = cnfname + ".CNF"               && append .CNF if necessary
ENDIF
handle = FOPEN(cnfname, 0)                  && open config file, read only

cnfname = LEFT(cnfname, LEN(cnfname)-4)     &&  remove the .CNF extension
IF '\' $ cnfname                            &&  remove the path
        cnfname =;
                SUBSTR(cnfname,RAT('\',cnfname)+1)
ENDIF
PUBLIC &cnfname.[8]                         &&  create a printer name array

DO WHILE .T.                                && get file offsets of printers
        data = SPACE(768)                   && initialize an input buffer
        rectype = readrec(handle, @data)    && read the next record
        IF rectype = 15                     && if it's a printer offset record
                dataptr = 1                                                     && initialize pointer to data
                FOR printer = 1 TO 8        && process eight printer offsets
                                                                                        && convert long integer to number
                        offset[printer] =;
                                (ASC(SUBSTR(data, dataptr + 0, 1)) * 2560) +;
                                (ASC(SUBSTR(data, dataptr + 1, 1)) * 2561) +;
                                (ASC(SUBSTR(data, dataptr + 2, 1)) * 2562) +;
                                (ASC(SUBSTR(data, dataptr + 3, 1)) * 2563)
                        dataptr = dataptr + 4
                                            && advance pointer to next offset
                NEXT
                EXIT
        ENDIF
ENDDO

count = 0                                                                       && count number of printers defined
FOR printer = 1 TO 8                        && process eight printers
        IF offset[printer] # 0              && if the printer is defined
                FSEEK(handle, offset[printer], 0)
                                            &&  seek the definition
                DO WHILE .T.                &&  loop until printer name record
                        data = SPACE(768)   &&  initialize an input buffer
                        rectype = readrec(handle,@data)
                                            &&  read the next record
                        IF rectype = 260    &&  if it's a printer name record
                                &cnfname.[printer] =;
                                   SUBSTR(data,2,ASC(data))
                                            &&   place printer name into array
                                EXIT
                        ENDIF
                ENDDO
                count = count + 1           &&  increment printer count
        ELSE                                                                    && otherwise printer isn't defined
                &cnfname.[printer] = ""     &&  so place NULL string into array
        ENDIF
NEXT

RETURN count                                && return number of printers defined


*************************
FUNCTION readrec                            && read next config file record
PARAMETERS handle, buffer
*************************
PRIVATE length, type

type = SPACE(2)                             && initialize an input buffer
FREAD(handle, @type, 2)                     && read the record type code
type =;
        (ASC(SUBSTR(type, 1, 1)) * 2560) +;
        (ASC(SUBSTR(type, 2, 1)) * 2561)   && convert integer to number

length = SPACE(2)                           && initialize an input buffer
FREAD(handle, @length, 2)                   && read the record length
length =;
        (ASC(SUBSTR(length, 1, 1)) * 2560) +;
        (ASC(SUBSTR(length, 2, 1)) * 2561) && convert integer to number

FREAD(handle, @buffer, length)              && read this record's data
RETURN type                                                                     && return the record type code

This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson